import React, { Component } from 'react';
import { connect } from 'react-redux';
import Util from "../../utils/Util";
import { TableOrderWarningList } from "../order/OrderTable";
import * as DataName from "../../action/DataNameConfig";
import { setCommonSystemLoading } from "../../action/Action";
import { GetOrderWarningList } from "../../action/ActionOrder";
import { Card, Select, DatePicker } from "antd";
const { RangePicker } = DatePicker;
const Option = Select.Option;

class Main extends Component {
    constructor(props) {
        super(props);
        this.state = {
            ...DataName.ORDER_WARNING_LIST_FILTER
        }
        this.onChangeTime=(date, dateString)=>{
            this.setState({
                startTime: dateString[0],
                endTime: dateString[1]
            },()=>{
                this.initData();
            })
        }
        this.handleSelectChangeArea=(value)=>{
            this.setState({
                area: !value?null:value
            },()=>{
                this.initData();
            })
        }
        this.initData=()=>{
            let { dispatch } = this.props;
            dispatch(setCommonSystemLoading(DataName.BASE_TABLE_LOADING,true));
            dispatch(GetOrderWarningList({...this.state}));
        }
    }
    componentWillMount(){
        Util.setMenuOpenKey(this.props,"warning");
        let { dispatch } = this.props;
        dispatch(setCommonSystemLoading(DataName.ORDER_WARNING_CARD_LOADING,true));
        this.initData();
    }
    render() {
        let { CommonSystem } = this.props;
        const optionArr = DataName.COMPANY_AREA_DATA.map(res=> <Option value={res.value}>{res.label}</Option>);
        return (
            <div className={"page-common"}>
                <Card title={"预警列表"} bordered={false} loading={CommonSystem[DataName.ORDER_WARNING_CARD_LOADING] || false}>
                    <div style={{paddingBottom: '20px'}}>
                        <Select defaultValue={0} style={{ width: 120 }} onChange={this.handleSelectChangeArea}>
                            <Option value={0}>按地区</Option>
                            {optionArr}
                        </Select>&nbsp;&nbsp;
                        <RangePicker onChange={this.onChangeTime} />&nbsp;&nbsp;
                    </div>
                    <TableOrderWarningList />
                </Card>
            </div>
        )
    }
}

export default connect(state=>({
    User: state.User,
    CommonSystem: state.CommonSystem,
    BaseData: state.BaseData
}))(Main);
